<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Create a new WriteConcern</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="mongodb-driver-writeconcern.bsonserialize.html">« MongoDB\Driver\WriteConcern::bsonSerialize</a></li>
      <li style="float: right;"><a href="mongodb-driver-writeconcern.getjournal.html">MongoDB\Driver\WriteConcern::getJournal »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.mongodb-driver-writeconcern.html">MongoDB\Driver\WriteConcern</a></li>
    <li>Create a new WriteConcern</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="mongodb-driver-writeconcern.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoDB\Driver\WriteConcern::__construct</h1>
  <p class="verinfo">(mongodb &gt;=1.0.0)</p><p class="refpurpose"><span class="refname">MongoDB\Driver\WriteConcern::__construct</span> &mdash; <span class="dc-title">Create a new WriteConcern</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongodb-driver-writeconcern.construct-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><strong>MongoDB\Driver\WriteConcern::__construct</strong></span>(<span class="methodparam"><span class="type"><span class="type">string</span>|<span class="type">int</span></span> <code class="parameter">$w</code></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">int</span><span class="type"></span></span> <code class="parameter">$wtimeout</code><span class="initializer"> = <strong><code>null</code></strong></span></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">bool</span><span class="type"></span></span> <code class="parameter">$journal</code><span class="initializer"> = <strong><code>null</code></strong></span></span>)</div>

  <p class="para rdfs-comment">
   Constructs a new <span class="classname"><a href="class.mongodb-driver-writeconcern.html" class="classname">MongoDB\Driver\WriteConcern</a></span>, which is
   an immutable value object.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-mongodb-driver-writeconcern.construct-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">w</code></dt>

    <dd>

     <p class="para">
      <table class="doctable table">
       <caption><strong>Write concern</strong></caption>
       
        <thead>
         <tr>
          <th>Value</th>
          <th>Description</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td>1</td>
          <td>
            Requests acknowledgement that the write operation has propagated to
            the standalone <code class="literal">mongod</code> or the primary in a replica
            set. This is the default write concern for MongoDB.
          </td>
         </tr>

         <tr>
          <td>0</td>
          <td>
           Requests no acknowledgment of the write operation. However, this may
           return information about socket exceptions and networking errors to
           the application.
          </td>
         </tr>

         <tr>
          <td>&lt;integer greater than 1&gt;</td>
          <td>
           Numbers greater than 1 are valid only for replica sets to request
           acknowledgement from specified number of members, including the
           primary.
          </td>
         </tr>

         <tr>
          <td><strong><code>MongoDB\Driver\WriteConcern::MAJORITY</code></strong></td>
          <td>
           <p class="para">
            Requests acknowledgment that write operations have propagated to the
            majority of voting nodes, including the primary, and have been
            written to the on-disk journal for these nodes.
           </p>
           <p class="para">
            Prior to MongoDB 3.0, this refers to the majority of replica set
            members (not just voting nodes).
           </p>
          </td>
         </tr>

         <tr>
          <td>string</td>
          <td>
           A string value is interpereted as a tag set. Requests acknowledgement
           that the write operations have propagated to a replica set member
           with the specified tag.
          </td>
         </tr>

        </tbody>
       
      </table>

     </p>
    </dd>

   
   
    <dt>
<code class="parameter">wtimeout</code></dt>

    <dd>

     <p class="para">
      How long to wait (in milliseconds) for secondaries before failing.
     </p>
     <p class="para">
      <code class="literal">wtimeout</code> causes write operations to return with an
      error (<span class="classname"><strong class="classname">WriteConcernError</strong></span>) after the specified
      limit, even if the required write concern will eventually succeed. When
      these write operations return, MongoDB does not undo successful data
      modifications performed before the write concern exceeded the
      <code class="literal">wtimeout</code> time limit.
     </p>
     <p class="para">
      If specified, <code class="literal">wtimeout</code> must be a signed 64-bit integer
      greater than or equal to zero.
     </p>
     <p class="para">
      <table class="doctable table">
       <caption><strong>Write concern timeout</strong></caption>
       
        <thead>
         <tr>
          <th>Value</th>
          <th>Description</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td>0</td>
          <td>Block indefinitely. This is the default.</td>
         </tr>

         <tr>
          <td>&lt;integer greater than 0&gt;</td>
          <td>
           Milliseconds to wait until returning.
          </td>
         </tr>

        </tbody>
       
      </table>

     </p>
    </dd>

   
   
    <dt>
<code class="parameter">journal</code></dt>

    <dd>

     <p class="para">
      Wait until mongod has applied the write to the journal.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 errors" id="refsect1-mongodb-driver-writeconcern.construct-errors">
  <h3 class="title">错误／异常</h3>
  <ul class="simplelist">
   <li class="member">Throws <span class="classname"><a href="class.mongodb-driver-exception-invalidargumentexception.html" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a></span> on argument parsing errors.</li>
   <li class="member">Throws <span class="classname"><a href="class.mongodb-driver-exception-invalidargumentexception.html" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a></span> if <code class="parameter">w</code> is invalid or <code class="parameter">wtimeout</code> is either negative or greater than the bounds of a signed 32-bit integer.</li>
  </ul>
 </div>


 <div class="refsect1 changelog" id="refsect1-mongodb-driver-writeconcern.construct-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>PECL mongodb 1.7.0</td>
       <td>
        The <code class="parameter">wTimeout</code> parameter now accepts 64-bit values.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>



 <div class="refsect1 examples" id="refsect1-mongodb-driver-writeconcern.construct-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1319">
   <p><strong>示例 #1 <span class="function"><strong>MongoDB\Driver\WriteConcern::__construct()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/*&nbsp;Request&nbsp;write&nbsp;acknowledgement&nbsp;from&nbsp;the&nbsp;majority&nbsp;of&nbsp;the&nbsp;replica&nbsp;set&nbsp;nodes&nbsp;*/<br /></span><span style="color: #0000BB">$wc&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">WriteConcern</span><span style="color: #007700">(</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">WriteConcern</span><span style="color: #007700">::</span><span style="color: #0000BB">MAJORITY</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">500</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Request&nbsp;write&nbsp;acknowledgement&nbsp;from&nbsp;a&nbsp;node&nbsp;configured&nbsp;with&nbsp;the&nbsp;"MultipleDC"&nbsp;tag&nbsp;*/<br /></span><span style="color: #0000BB">$wc&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">WriteConcern</span><span style="color: #007700">(</span><span style="color: #DD0000">"MultipleDC"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">500</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </div>



 <div class="refsect1 seealso" id="refsect1-mongodb-driver-writeconcern.construct-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><a href="https://www.mongodb.com/docs/manual/reference/write-concern/" class="link external">&raquo;&nbsp;Write Concern reference</a></li>
  </ul>
 </div>


</div></div></div></body></html>